package com.xieyong.leetcode;

import java.util.HashMap;
import java.util.Map;

public class Leetcode1394 {
    public static void main(String[] args) {
        Leetcode1394 leetcode = new Leetcode1394();
        int[] arr = {7,7,7,7,7,7,7};
        int lucky = leetcode.findLucky(arr);
        System.out.println(lucky);
    }


    public int findLucky(int[] arr) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i : arr) {
            map.put(i,map.getOrDefault(i,0)+1);
        }
        int res = -1;
        for (Integer i : map.keySet()) {
            if (map.get(i) == i) {
                res = Math.max(res,i);
            }
        }
        return res;
    }
}
